namespace Framework
{
    public class ParallelSelector<T> : Composite<T>
    {
        public override TaskStatus Update(T context)
        {
            bool didAllFail = true;
            int count = _children.Count;
            for (int i = 0; i < count; ++i)
            {
                Behavior<T> child = _children[i];
                child.Tick(context);
                if (child.status == TaskStatus.Success)
                {
                    return TaskStatus.Success;
                }

                if (child.status != TaskStatus.Failure)
                {
                    didAllFail = false;
                }
            }

            if (didAllFail)
            {
                return TaskStatus.Failure;
            }

            return TaskStatus.Running;
        }
    }
}